package com.xb.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xb.model.domain.dto.PageDTO;
import com.xb.model.domain.entity.FileUpload;
import com.xb.model.domain.vo.CompletedFileVO;
import com.xb.model.domain.vo.ErrorFileVO;
import com.xb.model.domain.vo.PendingFileVO;
import com.xb.system.common.result.Result;
import com.xb.system.service.FileUploadService;
import com.xb.system.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/file")
public class FileCheckController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("/pending")
    public Result<IPage<PendingFileVO>> getPendingFiles(@RequestBody PageDTO pageDTO) {
        Long userId = UserContext.getUserId();
        IPage<PendingFileVO> result = fileUploadService.getPendingFiles(userId, pageDTO);
        return Result.ok(result);
    }

    @PostMapping("/completed")
    public Result<IPage<CompletedFileVO>> getCompletedFiles(@RequestBody PageDTO pageDTO) {
        Long userId = UserContext.getUserId();
        IPage<CompletedFileVO> result = fileUploadService.getCompletedFiles(userId, pageDTO);
        return Result.ok(result);
    }

    @PostMapping("/error")
    public Result<IPage<ErrorFileVO>> getErrorFiles(@RequestBody PageDTO pageDTO) {
        Long userId = UserContext.getUserId();
        IPage<ErrorFileVO> result = fileUploadService.getErrorFiles(userId, pageDTO);
        return Result.ok(result);
    }

    @PostMapping("/delete/{fileId}")
    public Result<String> deleteFile(@PathVariable Long fileId) {
        fileUploadService.deleteFile(fileId);
        return Result.ok("删除成功");
    }
}